#include "dialog_fenshu.h"
#include "ui_dialog_fenshu.h"
#include <QPainter>
#include <QPropertyAnimation>
#include <QDesktopWidget>

dialog_fenshu::dialog_fenshu(QString str,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::dialog_fenshu)
{
    ui->setupUi(this);
    display_str=str;
    /*
    this->setFixedSize(500,500); //这句必须添加
    */


    int wd=parent->width();
    int ht=parent->height();
    this->move((wd-width())/2,(ht-height())/2);

    this->setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏
}

dialog_fenshu::~dialog_fenshu()
{
    delete ui;
}
void dialog_fenshu::showEvent(QShowEvent *event)
{
    QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "windowOpacity");
     pAnimation->setDuration(2000);
     pAnimation->setKeyValueAt(0, 1);
     pAnimation->setKeyValueAt(0.5, 0);
     pAnimation->setKeyValueAt(0.9, 0.9);
     pAnimation->setKeyValueAt(1, 0);
     pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
     connect(pAnimation,SIGNAL(finished()),this,SLOT(onfinished()));// 连接信号槽
}
void dialog_fenshu::onfinished()
{
    this->close();
}

void dialog_fenshu::paintEvent(QPaintEvent *p)
{
    Q_UNUSED(p);



        QPainter painter(this);
        // 设置画笔颜色
        painter.setPen(QColor("#DB4752"));

        // 设置字体：微软雅黑、点大小90、斜体
        QFont font;
        font.setFamily("Microsoft YaHei");
        font.setPointSize(90);
        font.setItalic(true);
        painter.setFont(font);

        // 绘制文本
        painter.drawText(rect(), Qt::AlignCenter, display_str);
}
